﻿using Avalonia.BiliBili.Libs.Models.View;
using Bilibili.Common.Log;
using Bilibili.Model.Channel;
using Bilibili.Model.Common;
using Bilibili.Model.Parts;
using PCLUntils.Objects;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace Avalonia.BiliBili.ViewModels
{
    public sealed class PartsViewModel : ViewModelBase
    {
        public int Current { get; set; } = 0;
        public List<Category> Categories { get; }
        private ObservableCollection<TagsModel> tags = [];
        private ObservableCollection<TabControlItem<DHModel>> items = [];
        public ObservableCollection<TabControlItem<DHModel>> Items
        {
            get => items;
            private set => this.RaiseAndSetIfChanged(ref items, value);
        }
        public ObservableCollection<TagsModel> Tags
        {
            get => tags;
            private set => this.RaiseAndSetIfChanged(ref tags, value);
        }
        public PartsViewModel()
        {
            Categories = new List<Category>();
        }
        public void InitCategory(List<RegionModel> regions)
        {
            try
            {
                if (regions.IsNotEmptyArray())
                {
                    for (var idx = 0; idx < regions.Count; idx++)
                    {
                        var region = regions.ElementAt(idx);
                        Categories.Add(new Category { Id = region.Tid, Content = region.Name, Tag = idx });
                        Items.Add(new TabControlItem<DHModel>(region.Name, idx));
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.Instance.LogError("InitCategory", ex);
            }
        }
    }
}